<?php

/* ----------------------------------------------
  Caloris: Administration Module Editor

  $Id$
  $Author$

  Nastavení modulů a editor nastavení modulů
  ---------------------------------------------- */

require_once("../../../index.php");
Caloris\ACL::authenticate();

define('_MODULE_ACTIVE', 'modulemanager');

$content = '
<h1>Moduly</h1>' . PHP_EOL;

$id = $_GET["id"];

$xmlModules = new Caloris\XML();
$xmlModules->source(_CALSET_PATHS_BASE . _CALSET_DIRS_DATA . '/modules.xml');
$xmlModules->filter('//module[@id="' . $id . '"]');

$content .= '
<h2>Moduly</h2>	

<table class="table table-striped" style="margin-top: 20px;">
';

if ($xmlModules->output[0]->hasadmin == 1) {
    if (file_exists(_CALSET_PATHS_BASE . _CALSET_DIRS_MODULE . '/' . $xmlModules->output[0]["id"] . '/index.php')) {
        $admin_startpage = '<a href="[cal:def(paths;uri) /]/cal-components/modules/' . $xmlModules->output[0]["id"] . '/index.php">Vstupte</a>';
    } else {
        $admin_startpage = 'Administrace modulu nenalezena: <em>' . _CALSET_PATHS_BASE . _CALSET_DIRS_MODULE . '/' . $xmlModules->output[0]["id"] . '/index.php</em>';
    }
} else {
    unset($admin_startpage);
}

$content .= '
    <tr>
        <td>Vstup do administrace</td>
        <td>' . $admin_startpage . '</td>
    </tr>
    <tr>
        <td>Jméno modulu</td>
        <td>' . $xmlModules->output[0]->name . '</td>
    </tr>
    <tr>
        <td>Popisek</td>
        <td>' . $xmlModules->output[0]->description . '</td>
    </tr>
</table>

<h2>Odstranění modulu</h2>' . PHP_EOL;

if (Caloris\ACL::authorize("modules") == 1) {
    $content .= '
<form action="' . _CALSET_PATHS_URI . _CALSET_DIRS_MODULE . '/modulemanager/index.php" method="post" enctype="multipart/form-data" style="text-align: left;">
<input type="hidden" name="function_name" value="module_uninstall" />
<table class="table table-striped">
    <tr>
        <td>Smazat extenze patřící k modulu</td>
        <td>Ano <input type="hidden" name="name" value="' . $id . '" /><input type="radio" name="del_ext" value="1" /> Ne <input type="radio" name="del_ext" value="0" checked="checked" /></td>
    </tr>
    <tr>
        <td>Napište dnešní datum ve formátu dd.mm. (pro kontrolu)</td>
        <td><input type="text" name="rand" style="width: 50px;" autocomplete="off" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="Odinstalovat" /></td>
    </tr>
</table>
</form>' . PHP_EOL;
} else {
    $content .= '<p>Nemáte oprávnění odinstalovat moduly</p>';
}

$data["title"] = 'Moduly: Detail';

$tmpl = new Caloris\Template;
$tmpl->input($content);
$tmpl->renderHead($data);
echo $tmpl->renderBody('caloris-admin');